package com.simple.datax.transform.tcs;

/**
 * @Title: Ec2TcsDecTransformer.java
 * @Package com.simple.datax.transform
 * @Description: 完成Declaration（报关单）报文内容到TCS的转换。
 *               目前EC的这段报文内容的标签是没有加前缀的，而TCS的报文标签是要加tcs:
 * @author Paladin Chen
 * @date 2013-1-7 下午5:57:50
 * @version V1.0
 */
public class Ec2TcsDecTransformer {

	public static String transform(String srcData) {
		// 针对无纸通关修改
		// 屏蔽PTS_SIGN，账册的报文 有可能是错误报文引起，正常报文，账册是不会出现在dec中的 2013-03-14
		if (srcData.toUpperCase().indexOf("<PTS_SIGN>") == -1) {
			if (srcData.indexOf("<tcs:") == -1) {
				srcData = srcData.replaceAll("<", "<tcs:").replaceAll("<tcs:/", "</tcs:");
			}
		}

		if (srcData.indexOf("<tcs:EdocID>") != -1 || srcData.indexOf("<EdocID>") != -1) {
			if (srcData.indexOf("<tcs:EdocID>") != -1) {
				int s = srcData.indexOf("<tcs:EdocID>");
				int e = srcData.indexOf("</tcs:EdocID>");

				String ECFileNameStr = srcData.substring(s + 11, e);

				String TCSFileNameStr = ECFileNameStr.replaceAll("ECP", "TCS");
				int length = srcData.length();
				srcData = srcData.substring(0, s + 11) + TCSFileNameStr + srcData.substring(e, length);
			} else {
				int s = srcData.indexOf("<EdocID>");
				int e = srcData.indexOf("</EdocID>");

				String ECFileNameStr = srcData.substring(s + 11, e);

				String TCSFileNameStr = ECFileNameStr.replaceAll("ECP", "TCS");
				int length = srcData.length();
				srcData = srcData.substring(0, s + 11) + TCSFileNameStr + srcData.substring(e, length);
			}

		}

		return srcData;
	}
}
